----------------------------------------------------------------------------------
-- Company: 
-- Engineer: 
-- 
-- Create Date:    13:00:44 04/22/2012 
-- Design Name: 
-- Module Name:    boundary_detector - Behavioral 
-- Project Name: 
-- Target Devices: 
-- Tool versions: 
-- Description: 
--
-- Dependencies: 
--
-- Revision: 
-- Revision 0.01 - File Created
-- Additional Comments: 
--
----------------------------------------------------------------------------------
library IEEE, work;
use IEEE.STD_LOGIC_1164.ALL;
use work.game_support.all;

-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;

-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity boundary_detector is
	Port (
		ball, paddle1, paddle2 : in position;
		collision : out collision_type;
		p1_inc, p2_inc : out std_logic
	);
end boundary_detector;

architecture Behavioral of boundary_detector is
	signal collision_internal : collision_type;
	
begin


process ( ball, paddle1, paddle2)
begin
	-- Defaul

		if (ball.x = 0) then
			collision_internal <= left_collision;
		elsif (ball.x = SCREEN_WIDTH) then 
			collision_internal <= right_collision;			
		elsif ((ball.x >= paddle1.x) and (ball.x <= (paddle1.x + PADDLE_BOUNDS.width)) and (ball.y = paddle1.y - BALL_SIZE)) then
			collision_internal <= paddle1_collision;
		elsif ((ball.x >= paddle2.x) and (ball.x <= (paddle2.x + PADDLE_BOUNDS.width)) and (ball.y = paddle2.y + BALL_SIZE)) then
			collision_internal <= paddle2_collision;
		elsif (ball.y = 0) then
			collision_internal <= top_collision;
		elsif (ball.y = SCREEN_HEIGHT) then
			collision_internal <= bottom_collision;
			
		else
			collision_internal <= none;
		end if;
		
		collision <= collision_internal;
end process;


	with collision_internal select p1_inc <=
		'1' when top_collision,
		'0' when others;
		
	with collision_internal select p2_inc <=
		'1' when bottom_collision,
		'0' when others;

end Behavioral;

